package com.site.web.controller.war;

import com.site.common.annotation.Log;
import com.site.common.core.controller.BaseController;
import com.site.common.core.domain.AjaxResult;
import com.site.common.core.page.TableDataInfo;
import com.site.common.enums.BusinessType;
import com.site.common.utils.poi.ExcelUtil;
import com.site.war.domain.SiteWarning;
import com.site.war.service.ISiteTowerService;
import com.site.war.service.ISiteWarningService;
import com.site.war.service.ISiteWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 预警信息Controller
 *
 * @author site
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/war/warning")
public class SiteWarningController extends BaseController
{
    @Autowired
    private ISiteWarningService siteWarningService;

    @Autowired
    private ISiteWorkService siteWorkService;

    @Autowired
    private ISiteTowerService siteTowerService;

    /**
     * 查询预警信息列表
     */
//    @PreAuthorize("@ss.hasPermi('site:warning:list')")
    @GetMapping("/list")
    public TableDataInfo list(SiteWarning siteWarning)
    {
        startPage();
        List<SiteWarning> list = siteWarningService.selectSiteWarningList(siteWarning);
        return getDataTable(list);
    }

    /**
     * 导出预警信息列表
     */
//    @PreAuthorize("@ss.hasPermi('site:warning:export')")
    @Log(title = "预警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SiteWarning siteWarning)
    {
        List<SiteWarning> list = siteWarningService.selectSiteWarningList(siteWarning);
        ExcelUtil<SiteWarning> util = new ExcelUtil<SiteWarning>(SiteWarning.class);
        util.exportExcel(response, list, "预警信息数据");
    }

    /**
     * 获取预警信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('site:warning:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(siteWarningService.selectSiteWarningById(id));
    }

    /**
     * 新增预警信息
     */
//    @PreAuthorize("@ss.hasPermi('site:warning:add')")
    @Log(title = "预警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SiteWarning siteWarning)
    {
        return toAjax(siteWarningService.insertSiteWarning(siteWarning));
    }

    /**
     * 修改预警信息
     */
//    @PreAuthorize("@ss.hasPermi('site:warning:edit')")
    @Log(title = "预警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SiteWarning siteWarning)
    {
        return toAjax(siteWarningService.updateSiteWarning(siteWarning));
    }

    /**
     * 删除预警信息
     */
//    @PreAuthorize("@ss.hasPermi('site:warning:remove')")
    @Log(title = "预警信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(siteWarningService.deleteSiteWarningByIds(ids));
    }

    /**
     * ZYJ
     * 今日项目预警趋势图
     * @return
     */
    @GetMapping("/getTodayWarningTrend")
    public AjaxResult getTodayWarningTrend(){
        return success(siteWarningService.getTodayWarningTrend());
    }



    /**
     * ZYJ
     * 机械设备隐患占比
     * @return
     */
    @GetMapping("/getDeviceWarningProportion")
    public AjaxResult getDeviceWarningProportion(){
        return success(siteWarningService.getDeviceWarningProportion());
    }

    /**
     * ZYJ
     * 一年每周预警数量
     * @return
     */
    @GetMapping("getWarningYearWeek")
    public AjaxResult getWarningYearWeek(){
        return success(siteWarningService.getWarningYearWeek());
    }

    /**
     * ZYJ
     * 一年每月预警数量
     * @return
     */
    @GetMapping("getWarningYearMonth")
    public AjaxResult getWarningYearMonth(){
        return success(siteWarningService.getWarningYearMonth());
    }


    /**
     * ZYJ
     * 隐患治理情况1
     * @return
     */
    @GetMapping("getWarningManageOne")
    public AjaxResult getWarningManageOne(){
        return success(siteWarningService.getWarningManageOne());
    }

    /**
     * ZYJ
     * 隐患治理情况2
     * @return
     */
    @GetMapping("getWarningManageTwo")
    public AjaxResult getWarningManageTwo(){
        return success(siteWarningService.getWarningManageTwo());
    }


    /**
     * ZYJ
     * 预警情况
     * @return
     */
    @GetMapping("getWarningType")
    public AjaxResult getWarningType(){
        return success(siteWarningService.getWarningType());
    }

    /**
     * ZYJ
     * 获取概况
     * @return
     */
    @GetMapping("getStatistics")
    public AjaxResult getStatistics(){

        Map<String,Integer> map=new HashMap<>();
        int work = siteWorkService.getAllCount();
        int tower = siteTowerService.getAllCount();
        int warning = siteWarningService.getAllCount();

        map.put("work",work);
        map.put("tower",tower);
        map.put("basket",0);
        map.put("lift",0);
        map.put("warning",warning);

        return success(map);
    }
}
